/*----------------------------------------------------------------------------
 * CMSIS-RTOS 'main' function template
 *---------------------------------------------------------------------------*/
#include "systick.h"
#define osObjectsPublic  // define objects in main module
#include "osObjects.h"   // RTOS object definitions
#include "Drv_Fwdgt.h"
#include "global.h"

/**/
#ifdef SA
osThreadId tid_TemperatureHumidity;  //温湿度进程
#else
osThreadId tid_Power;  //电源检测进程
#endif
osThreadId tid_Communiction;  //通信进程
osThreadId tid_BackGround;    //后台进程
#ifdef SA
osThreadDef(TemperatureHumidity_Proc, osPriorityNormal, 1, 0);
#else
osThreadDef(Power_Proc, osPriorityNormal, 1, 0);
#endif
osThreadDef(Communiction_proc, osPriorityNormal, 1, 0);
osThreadDef(BackGround_proc, osPriorityLow, 1, 0);

/*
 * main: initialize and start the system
 */
uint32_t main_error_code = 0;
osThreadId main_error_id = 0;
int main(void)
{
    osKernelInitialize();  // initialize CMSIS-RTOS
    irc40k_config();
    systick_config();
    // initialize peripherals here
    tid_Communiction = osThreadCreate(osThread(Communiction_proc), NULL);
    tid_BackGround   = osThreadCreate(osThread(BackGround_proc), NULL);
#ifdef SA
    g_sVariable.u8SA        = 0x01;
    tid_TemperatureHumidity = osThreadCreate(osThread(TemperatureHumidity_Proc), NULL);
#else
    g_sVariable.u8SA = 0x00;
    tid_Power        = osThreadCreate(osThread(Power_Proc), NULL);  //创建电源检测任务
#endif
    // create 'thread' functions that start executing,
    // example: tid_name = osThreadCreate (osThread(name), NULL);

    osKernelStart();  // start thread execution
}

#ifdef USE_FULL_ASSERT
/**
 * [url=home.php?mod=space&uid=247401]@brief[/url]  Reports the name of the source file and the source line number
 *         where the assert_param error has occurred.
 * @param  file: pointer to the source file name
 * @param  line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t* file, uint32_t line)
{
    /* User can add his own implementation to report the file name and line number,
       ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

    /* Infinite loop */
    while (1)
    {
    }
}
#else
void __aeabi_assert(const char* x1, const char* x2, int x3)
{
    while (1)
    {
    }
}
#endif
